*******  This file replicate Table 5, Figure 2, Table 6 in the main analysis and Table A16, A17, and A18 in the appendix


use "gtd_group.dta" , clear

  

eststo clear


** replace attack_total = 320 in 12
** BIFF only has 320 attacks in total; not 476

foreach var in rebestimate  {
	replace `var'="." if `var'=="NA"
	destring, replace
}

**** end loop


**** gen rebal strength
gen relativeStrength=0
replace relativeStrength=1 if rebstrength=="parity" |rebstrength=="weaker"


*** gen centrol command
gen centrolcommand=0
replace centrolcommand=1 if centcontrol=="yes"

*** whether the group has a strong (moderate) control over its subgroup
gen controlsubgroup=0
replace controlsubgroup=1 if strengthcent =="moderate" | strengthcent =="high"

**** territory
gen territory=0
replace territory=1 if terrcont =="yes"


*** external non-state support, non-military
gen nonmilitary_support=0
replace nonmilitary_support=1 if transconstsupp =="explicit"

*** external non-state military support
gen military_support=0
replace military_support=1 if rebextpart =="alleged" | rebextpart=="major" | rebextpart=="minor" 


*** rebel numbers: based on our coding
replace rebestimate=60000 if side_b=="Patani insurgents"
replace rebestimate=1300 if side_b=="Jundallah"
replace rebestimate=500 if side_b=="Bangsamoro Islamic Freedom Movement (BIFM)"

gen size=log(rebestimate)

*** institutionalization
gen institution=centrolcommand + controlsubgroup
 

*** foreign non-state support
gen support_nonstate=0
replace  support_nonstate=1 if nonmilitary_support==1 | military_support==1

*** generate foreign gov support
gen support_foreigngov=0
replace support_foreigngov=1 if rebelsupport=="alleged" | rebelsupport=="explicit"


*** generate political wing
gen political_wing=.
replace political_wing=0 if rebpolwing=="no"
replace political_wing=1 if rebpolwing=="acknowledged link" | rebpolwing=="alleged link" | rebpolwing=="explicit link" 



*** control for conflict type
gen secessionist=0
replace secessionist=1 if conflicttype=="secessionist conflict" | conflicttype=="autonomy conflict"

** FIAA has missing values on institution
replace institution=. if side_b=="FIAA"



**************
label var institution "Institutionalization"
label var territory "Territory control"
label var relativeStrength "Relative strength"
label var support_nonstate "Foreign third-party support"
label var support_foreigngov "Foreign gov support"
label var political_wing "Political wing"
label var salafijihadism "Salafi jihadism"
label var secessionist "Secessionist"


*** Table 5
*** export sumary table
estpost sum ratio institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist

esttab . using Table_5.tex, cells("mean(fmt(3)) sd(fmt(3)) min max(fmt(3)) count") replace noobs




*** Table 6
*** regressions
eststo clear

eststo: quietly  reg  ratio institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit  ratio institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total], vce (cluster side_a)

eststo: quietly  reg  ratio institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  vce (cluster side_a)

eststo: quietly  reg  ratio institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  vce (cluster side_a)

esttab using Table_6.tex,  se b(3) replace booktabs ///
  alignment(D{.}{.}{-1})                         ///
  title(Pooled Regression table\label{tab1})


  
**** Figure 2  
**** margins plot
eststo clear
quietly fracreg logit   ratio institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  vce (cluster side_a)
margins, at(institution=(0(1)2)) noatlegend
marginsplot, yline(0) title("Preditive Margins with 95% CIs")  saving(Figure_2, replace)
  

  

  
************  Table A11: External Validity: One-Sided Violence
eststo clear


eststo: quietly  reg  ratio_OSV institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit  ratio_OSV institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total], vce (cluster side_a)

eststo: quietly  reg  ratio_OSV institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio_OSV institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  vce (cluster side_a)

eststo: quietly  reg  ratio_OSV institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio_OSV institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  vce (cluster side_a)

esttab using Table_A11.tex,  se b(3) replace booktabs ///
  alignment(D{.}{.}{-1})                         ///
  title(Pooled Regression table\label{tab1})





  
 
  
  
************  Table A16: Macrolevel Analysis: Attack Ratio during Christian Holidays
  
************  placebo test
eststo clear


eststo: quietly  reg  ratio_Christ institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit  ratio_Christ institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total], vce (cluster side_a)

eststo: quietly  reg  ratio_Christ institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio_Christ institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  vce (cluster side_a)

eststo: quietly  reg  ratio_Christ institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio_Christ institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  vce (cluster side_a)


esttab using Table_A16.tex,  label se b(3) replace booktabs ///
  alignment(D{.}{.}{-1})                         ///
  title(Pooled Regression table\label{tab1})  

  
  
  
************  Table A17: Macrolevel Analysis: Attack Ratio during Buddhist Holidays
************  placebo test
    
eststo clear


eststo: quietly  reg  ratio_Buddhist institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit  ratio_Buddhist institution relativeStrength territory support_nonstate  support_foreigngov    [pweight=attack_total], vce (cluster side_a)

eststo: quietly  reg  ratio_Buddhist institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio_Buddhist institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism   [pweight=attack_total],  vce (cluster side_a)

eststo: quietly  reg  ratio_Buddhist institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  r cluster(side_a)

eststo: quietly  fracreg logit   ratio_Buddhist institution relativeStrength territory support_nonstate  support_foreigngov political_wing salafijihadism  secessionist [pweight=attack_total],  vce (cluster side_a)


esttab using Table_A17.tex,  label se b(3) replace booktabs ///
  alignment(D{.}{.}{-1})                         ///
  title(Pooled Regression table\label{tab1})    
  

  
***** Table A18: List of Rebel Groups
eststo clear
asdoc  l side_b attack_total, save(Table_A18.doc) replace

  
  